# Michael Depuy
# depuym@onid.orst.edu
# CS311-400
# Homework 2


import subprocess
import shlex
import os
import sys
import stat
import time
import getopt


def mkdirs():
    command = "ln -s"
    command_sequence = shlex.split(command)
    term = ""
    for i in sys.argv:
        if i == "-t" or i == "--term":
            term = sys.argv[sys.argv.index(i)+1]
            break

    section = ""
    for i in sys.argv:
        if i == "-c" or i == "--class":
            section = sys.argv[sys.argv.index(i)+1]
            break
    
    command_sequence.append("/usr/local/classes/eecs/"+term+"/"+section+"/src/README.txt")
    command_sequence.append("README")

    subprocess.Popen(command_sequence)


    command = "ln -s"
    command_sequence = shlex.split(command)
    term = ""
    for i in sys.argv:
        if i == "-t" or i == "--term":
            term = sys.argv[sys.argv.index(i)+1]
            break

    section = ""
    for i in sys.argv:
        if i == "-c" or i == "--class":
            section = sys.argv[sys.argv.index(i)+1]
            break
    
    command_sequence.append("/usr/local/classes/eecs/"+term+"/"+section+"/src/")
    command_sequence.append("src_class")

    subprocess.Popen(command_sequence)

    


    print "Making directories..."
    print "assignments"
    print "examples"
    print "exams"
    print "lecture_notes"
    print "submissions"

    command = "mkdir"
    command_sequence = shlex.split(command)
    options = "null"

    while(options != "n") or (options != ""): 
        options = raw_input("Would you like to put these folders into a subdirectory?[y,n]: ")
        if options == "y":
            options = raw_input("Directory(ex './d1/d2/d3/'): ")
            break
        if options == "n":
            break

    if options != "" and options != "n":
        command_sequence.append(options+"assignments")
        subprocess.Popen(command_sequence)
        command_sequence.pop()
        command_sequence.append(options+"examples")
        subprocess.Popen(command_sequence)
        command_sequence.pop()
        command_sequence.append(options+"exams")
        subprocess.Popen(command_sequence)
        command_sequence.pop()
        command_sequence.append(options+"lecture_notes")
        subprocess.Popen(command_sequence)
        command_sequence.pop()
        command_sequence.append(options+"submissions")
        subprocess.Popen(command_sequence)
    else:
        command_sequence.append("assignments")
        subprocess.Popen(command_sequence)
        command_sequence.pop()
        command_sequence.append("examples")
        subprocess.Popen(command_sequence)
        command_sequence.pop()
        command_sequence.append("exams")
        subprocess.Popen(command_sequence)
        command_sequence.pop()
        command_sequence.append("lecture_notes")
        subprocess.Popen(command_sequence)
        command_sequence.pop()
        command_sequence.append("submissions")
        subprocess.Popen(command_sequence)
   

    

    

if __name__ == '__main__':
    mkdirs()
    
